#ifndef _UVP_H
#define _UVP_H

#include <math.h>

#include "helper.h"
#include "cfd_utils.h"



/*

=========================================================================================

 This file contains the declarations of the *core* methods to be used in the application

=========================================================================================

*/



/**
 * The step size dt for the next time step is calculated according to (13) in worksheet 1. In case of negative tau, the stepsize to be read in read_parameters should be used.
 * @param 	Re 	Reynolds Number
 * @param 	tau 	Safety factor for calculating the time step
 * @param 	dt 	the time step to be calculated
 * @param 	dx 	length of one cell in x-direction
 * @param 	dy 	length of one cell in y-direction
 * @param 	imax 	Number of interior cells in x-direction
 * @param 	jmax 	Number of interior cells in y-direction
 * @param 	U 	The velocity in x-direction
 * @param 	V 	The velocity in y-direction
 *
 * @author Mohamed Ibrahim
 */
void calculate_dt(double Re,
                  double tau,
		  double *dt,
                  double dx,
		  double dy,
		  int imax,
		  int jmax,
		  double **U,
		  double **V
		  );

/**
 * Computation of F and G according to the equations number (9) and (10) in worksheet # 1. Formula (17) must be applied at the boundary.
 *
 * @param 	Re 	Reynolds Number
 * @param 	GX 	external forces component in x-direction
 * @param 	GY 	external forces component in y-direction
 * @param 	alpha 	upwind differening factor (see equation (4) in worksheet 1)
 * @param 	dt 	the time step to be calculated
 * @param 	dx 	length of one cell in x-direction
 * @param 	dy 	length of one cell in y-direction
 * @param 	imax 	Number of interior cells in x-direction
 * @param 	jmax 	Number of interior cells in y-direction
 * @param 	U 	The velocity in x-direction
 * @param 	V 	The velocity in y-direction
 * @param 	F 	F-component of the pressure equation
 * @param 	G 	G-component of the pressure equation
 * @param	Flag	The fluid-obstacle flags matrix
 *
 * @author Mohamed Bamakhrama
 */
void calculate_fg(double Re,
		  double GX,
		  double GY,
		  double alpha,
		  double dt,
		  double dx,
		  double dy,
		  int imax,
		  int jmax,
		  double **U,
		  double **V,
		  double **F,
		  double **G,
		  int **Flag
		  );

/**
 * The new velocities are computed according to (7) and (8) in worksheet 1.
 * @param 	dt 	the time step to be calculated
 * @param 	dx 	length of one cell in x-direction
 * @param 	dy 	length of one cell in y-direction
 * @param 	imax 	Number of interior cells in x-direction
 * @param 	jmax 	Number of interior cells in y-direction
 * @param 	U 	The velocity in x-direction
 * @param 	V 	The velocity in y-direction
 * @param 	F 	F-component of the pressure equation
 * @param 	G 	G-component of the pressure equation
 * @param 	P 	The pressure matrix
 * @param	Flag	The fluid-obstacle flags matrix
 *
 * @author Mohamed Bamakhrama
 */
void calculate_uv(double dt,
		  double dx,
		  double dy,
		  int imax,
		  int jmax,
		  double **U,
		  double **V,
		  double **F,
		  double **G,
		  double **P,
		  int **Flag
		  );

/**
 * Computes the right-hand side of the pressure equation according to equation (11) of worksheet 1.
 *
 * @param 	dt 	the time step to be calculated
 * @param 	dx 	length of one cell in x-direction
 * @param 	dy 	length of one cell in y-direction
 * @param 	imax 	Number of interior cells in x-direction
 * @param 	jmax 	Number of interior cells in y-direction
 * @param 	F 	F-component of the pressure equation
 * @param 	G 	G-component of the pressure equation
 * @param 	RS 	Right hand side of the pressure equation
 * @param 	Flag 	The fluid/obstacle flags matrix
 *
 * @author Mohamed Bamakhrama
 */
void calculate_rs(
		  double dt,
		  double dx,
		  double dy,
		  int imax,
		  int jmax,
		  double **F,
		  double **G,
		  double **RS,
		  int **Flag
		 );

/*
=======================================================================

The following methods are used within calculate_fg but are not specified in the worksheet

=======================================================================
*/

/**
 * Calculates the convection in the x-direction
 *
 * @param 	i 	The x-coordinate to be used in the calculation
 * @param 	j 	The y-coordinate to be used in the calculation
 * @param 	dx 	The cell length in x-direction
 * @param 	dy 	The cell length in y-direction
 * @param 	alpha 	Upwind differencing factor
 * @param 	U 	The velocity matrix in the x-direction
 * @param 	V 	The velocity matrix in the y-direction
 *
 * @author Mohamed Ibrahim
 */
inline double calculate_convection_x(int i,
			     int j,
			     double dx,
			     double dy,
			     double alpha,
			     double **U,
			     double **V
			    );
/**
 * Calculates the convection in the y-direction
 *
 * @param 	i 	The x-coordinate to be used in the calculation
 * @param 	j 	The y-coordinate to be used in the calculation
 * @param 	dx 	The cell length in x-direction
 * @param 	dy 	The cell length in y-direction
 * @param 	alpha 	Upwind differencing factor
 * @param 	U 	The velocity matrix in the x-direction
 * @param 	V 	The velocity matrix in the y-direction
 *
 * @author Mohamed Ibrahim
 */
inline double calculate_convection_y(int i,
			     int j,
			     double dx,
			     double dy,
			     double alpha,
			     double **U,
			     double **V
			    );

/**
 * Calculates the diffusion
 *
 * @param 	Re 	Reynolds Number
 * @param 	i 	The x-coordinate
 * @param 	j 	The y-coordinate
 * @param 	dx 	The cell length in x-direction
 * @param 	dy 	The cell length in y-direction
 * @param 	M 	The matrix to be used to calculate the diffusion
 *
 * @author Mohamed Bamakhrama
 */
inline double diffusion(double Re,
		 int i,
		 int j,
		 double dx,
		 double dy,
		 double **M
		 );


#endif
